﻿using System;
using System.Web.Routing;

namespace EmptyWallGallery.FrontEnd
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);

            // Code that runs on application startup
            //var path = Configs.FolderSaveData + "Count.txt";
            //if (!File.Exists(path))
            //    File.WriteAllText(path, "0");

            //Application["Access"] = int.Parse(File.ReadAllText(path));
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            //var path = Configs.FolderSaveData + "Count.txt";
            //// Code that runs when a new session is started
            //if (Application["Online"] == null)
            //    Application["Online"] = 1;
            //else
            //    Application["Online"] = (int)Application["Online"] + 1;

            //Application["Access"] = (int)Application["Access"] + 1;
            //File.WriteAllText(path, Application["Access"].ToString());
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends.
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer
            // or SQLServer, the event is not raised.
            //var i = (int)Application["Online"];
            //if (i > 1)
            //    Application["Online"] = i - 1;

            //var path = Configs.FolderSaveData + "Count.txt";
            //File.WriteAllText(path, Application["Access"].ToString());
        }

        protected void Application_End(object sender, EventArgs e)
        {
            // Code that runs on application shutdown
            //var path = Configs.FolderSaveData + "Count.txt";
            //File.WriteAllText(path, Application["Access"].ToString());
        }

        private static void RegisterRoutes(RouteCollection routes)
        {
            //    // Register a route for Categories/All
            //    // Route name
            //    // Route URL
            //    // Web page to handle route
            routes.MapPageRoute("Intro", "about", "~/Intro.aspx");
            routes.MapPageRoute("Contact", "contact", "~/Contact.aspx");
            routes.MapPageRoute("artists", "artists", "~/Artists.aspx");
            routes.MapPageRoute("ArtistsDetail", "artists/{AlbumId}_{AlbumName}", "~/ArtistsDetail.aspx");
            routes.MapPageRoute("exhibitions", "exhibitions", "~/Exhibitions.aspx");
            //    routes.MapPageRoute("Vote", "Service/Vote", "~/Services/Vote.aspx");
            //    routes.MapPageRoute("FeedBack", "Home/Feedback", "~/Feedback.aspx");
            //    routes.MapPageRoute("Search", "Home/Search", "~/Search.aspx");
            //    routes.MapPageRoute("Transaction", "Home/Transaction", "~/Transaction.aspx");
            //    routes.MapPageRoute("TransactionProc", "Home/Transaction-Proc", "~/TransactionProc.aspx");
            routes.MapPageRoute("Error", "Error", "~/Error.aspx");
            //    routes.MapPageRoute("Download", "Service/Download", "~/Services/Download.aspx");
            routes.MapPageRoute("ArticleCategory", "c{CatID}s{SubCat}/{*CategoryName}", "~/Category.aspx");
            //    routes.MapPageRoute("ArticleCategory2", "c{CatID}s{SubCat}x{SubCatx}/{*CategoryName}", "~/Category.aspx");
            routes.MapPageRoute("Article", "{Year}/{Month}/{Day}/{Title}-{ArticleID}", "~/Article.aspx");

            //    // Route to handle Categories/{CategoryName}.
            //    // The {*CategoryName} instructs the route to match all content after the first slash, which is needed b/c some category names contain a slash, as in the category "Meat/Produce"
            //    // See http://forums.asp.net/p/1417546/3131024.aspx for more information
            //    // Route name
            //    // Route URL
            //    // Web page to handle route
            //    //routes.MapPageRoute("View Category", "Categories/{*CategoryName}", "~/CategoryProducts.aspx")

            //    // Register a route for Products/{ProductName}
            //    // Route name
            //    // Route URL
            //    // Web page to handle route
            //    //routes.MapPageRoute("View Product", "Products/{ProductName}", "~/ViewProduct.aspx")
        }
    }
}